//
//  Person.m
//  Memory2
//
//  Created by cora1n on 14-8-11.
//  Copyright (c) 2014年 devwu. All rights reserved.
//

#import "Person.h"

@implementation Person
-(void)setCar:(Car *)car
{
    //对新值进行增持
    [car retain];
    //对旧值进行减持
    if (_car != nil)
    {
        [_car release];
    }
    _car = car;
}
-(Car *)car
{
    return _car;
}

-(Car *)someCar
{
    //通常,谁alloc 谁负责 release
    Car * car = [[[Car alloc]init] autorelease];
    car.brand = @"some";
    //car的释放有self管理,但是什么时候释放,由系统决定
    //自动释放池
//    autorelase方法, 将对象放入到最新的池中
    //反正该对象,迟早都要release,只不错,relaese的时刻不太确定
    //延迟释放
    return car;
}

-(Person *)initWithName:(NSString *)name
{
    if (self = [super init]) {
        self.name = name;
    }
    return self;
}
+(Person *)personWithName:(NSString *)name
{
    Person * p = [[Person alloc]initWithName:name];
    return [p autorelease];
}

@end
